<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/contosoMap">
		<xsl:if test="map">
			<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
			<script type="text/javascript">
				var map = null;
				var pinID = 1;

				function onFoundResults()
				{
				var pin = new VEPushpin
				(
				pinID,
				map.GetCenter(),
				null,
				'<xsl:value-of select="map/foundLocationLabel"/>',
				'<xsl:value-of select="map/qsIs" />',
				'link-item',
				'description'
				);
				map.AddPushpin(pin);
				pinID++;
				}

				function GetInitialMap() {
				map = new VEMap('myMap');
				map.LoadMap(new VELatLong(47.6, -122.33), 18 ,'r' ,false);
				}
				function GetRequestedMap() {
				map = new VEMap('myMap');
				map.ShowDisambiguationDialog(false);
				map.LoadMap(new VELatLong(0.0, 0.0), 1 ,'r' ,false);
				map.FindLocation(document.all('<xsl:value-of select="map/clientId" />').value, onFoundResults);
				}
				// TODO: Categories hard-coded for demo purposes. In a real scenario they should be retrieved
				// from Contoso Business Directory
				function FindNearby() {
				map.DeleteAllPushpins();
				if (document.all('cbRestaurants').checked)
				map.Find('Restaurant');
				if (document.all('cbCinemas').checked)
				map.Find('Cinema');
				}

				function FindLoc() {
				map.FindLocation(document.all('<xsl:value-of select="map/clientId" />').value);
				}
			</script>
			<table cellspacing="10" cellpadding="0" border="0" width="100%" height="100%">
				<colgroup>
					<col width="500"/>
					<col width="200"/>
				</colgroup>
				<tr>
					<td colspan="2">
						<div class="description">
							<xsl:value-of select="map/addressExample" />
						</div>
						<div class="description">
							<table width="100%" cellpadding="0" cellspacing="0">
								<tr>
									<td width="100%">
										<xsl:value-of select="map/location" disable-output-escaping="yes" />
									</td>
									<td>
										<input type="button" class="ms-long" style="width: 50px" onclick="FindLoc()">
											<xsl:attribute name="value">
												<xsl:value-of select="map/findLocLabel"/>
											</xsl:attribute>
										</input>
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
				<tr>
					<td width="500">
						<div id='myMap' style="position:relative; width:500px; height:350px;"></div>
					</td>
					<td width="200px" valign="top">
						<div class="description">
							<input type="checkbox" id="cbRestaurants">Restaurants</input>
							<br/>
							<input type="checkbox" id="cbCinemas">Cinemas</input>
							<br/>
							<br/>
							<br/>
							<a href="javascript:FindNearby()">
								<xsl:value-of select="map/searchNearByLabel" />
							</a>
						</div>
					</td>
				</tr>
			</table>
			<script type="text/javascript">
				<xsl:if test="map/qsIs != ''">
					this.document.body.onload = GetRequestedMap;
				</xsl:if>
				<xsl:if test="map/qsIs = ''">
					this.document.body.onload = GetInitialMap;
				</xsl:if>
			</script>
		</xsl:if>
		<xsl:if test="errors">
			<xsl:for-each select="errors/error">
				<div class="description">
					<br/>
					<xsl:value-of select="../errorLabel"/>
					<b>
						<xsl:value-of select="."/>
					</b>
					<br/>
				</div>
			</xsl:for-each>
			<div class="description">
				<br/>
				<xsl:value-of select="errors/errorComments"/>
				<br/>
			</div>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>